-
An
MGLStyleAnnotationControlleris the object responsible for adding, removing, and updatingMGLStyleAnnotations on a map.Do not create instances of
See moreMGLStyleAnnotationControllerdirectly. Instead, create an instance ofMGLCircleAnnotationController,MGLLineAnnotationController,MGLPolygonAnnotationController, orMGLSymbolAnnotationControllerand use-[MGLAnnotationController addShape:]or-[MGLStyleAnnotationController addShapes:]to add shapes to anMGLMapView.Declaration
Objective-C
@interface MGLAnnotationController : NSObjectSwift
class MGLAnnotationController : NSObject
-
An
MGLCircleAnnotationControlleris a controller that creates internally instances of anMGLShapeSourceandMGLCicleStyleLayerto simplify the creation of runtime styling based annotations to the map.Create instances of
MGLCircleStyleAnnotationand pass it to this controller to add circular shapes to anMGLMapView.Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let circleAnnotationController = MGLCircleAnnotationController(mapView: self.mapView) let circle = MGLCircleStyleAnnotation(center: CLLocationCoordinate2D(latitude: 59.31, longitude: 18.06), radius: 3.0, color: .blue) circle.opacity = 0.5 circleAnnotationController.add(circle) }Declaration
Objective-C
@interface MGLCircleAnnotationController : MGLAnnotationControllerSwift
class MGLCircleAnnotationController : MGLAnnotationController
-
An
MGLLineAnnotationControlleris a controller that creates internally instances of anMGLShapeSourceandMGLLineStyleLayerto simplify the creation of runtime styling based annotations to the map.Create instances of
MGLLineStyleAnnotationand pass it to this controller.Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let lineAnnotationController = MGLLineAnnotationController(mapView: self.mapView) let lineCoordinates = [ CLLocationCoordinate2D(latitude: 59, longitude: 18), CLLocationCoordinate2D(latitude: 60, longitude: 20) ] let line = MGLLineStyleAnnotation(coordinates: lineCoordinates, count: UInt(lineCoordinates.count)) line.color = .purple lineAnnotationController.add(line) }Declaration
Objective-C
@interface MGLLineAnnotationController : MGLAnnotationControllerSwift
class MGLLineAnnotationController : MGLAnnotationController
-
An
MGLPolygonAnnotationControlleris a controller that creates internally instances of anMGLShapeSourceandMGLFillStyleLayerto simplify the creation of runtime styling based annotations to the map.Create instances of
MGLPolygonStyleAnnotationand pass it to this controller.Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let polygonAnnotationController = MGLPolygonAnnotationController(mapView: self.mapView) let polygonCoordinates = [ CLLocationCoordinate2DMake(59, 18), CLLocationCoordinate2DMake(62, 19), CLLocationCoordinate2DMake(54, 20), CLLocationCoordinate2DMake(59, 18) ] let polygon = MGLPolygonStyleAnnotation(coordinates: polygonCoordinates, count: UInt(polygonCoordinates.count)) polygon.fillOutlineColor = .red polygonAnnotationController.add(polygon) }Declaration
Objective-C
@interface MGLPolygonAnnotationController : MGLAnnotationControllerSwift
class MGLPolygonAnnotationController : MGLAnnotationController
-
An
MGLSymbolAnnotationControlleris a controller that creates internally instances of anMGLShapeSourceandMGLSymbolStyleLayerto simplify the creation of runtime styling based annotations to the map.Create instances of
MGLSymbolStyleAnnotationand pass it to this controller.An image must be supplied to the map style’s sprite before being able to assign it to be the icon image of a symbol.
Example
See morefunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { let attraction = UIImage(named: "attraction") if let styleImage = attraction { self.mapView.style?.setImage(styleImage, forName: "attraction") } let symbolAnnotationController = MGLSymbolAnnotationController(mapView: self.mapView) let symbol = MGLSymbolStyleAnnotation(coordinate: CLLocationCoordinate2DMake(59, 18)); symbol.iconImageName = "attraction" symbol.text = "This is a cool place!" symbol.textFontSize = 16 symbolAnnotationController.add(symbol) }Declaration
Objective-C
@interface MGLSymbolAnnotationController : MGLAnnotationControllerSwift
class MGLSymbolAnnotationController : MGLAnnotationController
Annotation controllers Reference